package com.hndzyu.yd.task;

import android.app.Activity;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.gyf.barlibrary.ImmersionBar;
import com.hndzyu.yd.R;
import com.hndzyu.yd.bean.UserBean;
import com.hndzyu.yd.url.Path;

/**
 * Created by zz9527 on 2018/10/23.
 */
public class FollowActivity extends Activity  {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_follow);
        ImmersionBar.with(this).statusBarColor(R.color.them)
                .init();
        ImageView iv = findViewById(R.id.iv);
        TextView title = findViewById(R.id.title);
//        TextView one = findViewById(R.id.one);
        TextView all = findViewById(R.id.all);
        TextView tv = findViewById(R.id.tv);
        TextView tv1 = findViewById(R.id.tv1);
        TextView tv2 = findViewById(R.id.tv2);
        final TextView tv3=findViewById(R.id.tv3);
        final TextView follow_num = findViewById(R.id.tv_follow_num);
        final TextView follow_id = findViewById(R.id.tv_follow_id);
        findViewById(R.id.backarea).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        Intent intent = getIntent();
        RequestOptions requestOptions = RequestOptions.circleCropTransform();
        Glide.with(this).load(Path.img(intent.getStringExtra("iv"))).apply(requestOptions).into(iv);
        title.setText(intent.getStringExtra("title"));
        if ("0".equals(intent.getStringExtra("num"))){
            tv.setText(Html.fromHtml("每邀请一个好友关注获得<font color='#ff0000'>"+intent.getStringExtra("one")+"</font>元"));
        }else {
            tv.setText(Html.fromHtml("已成功邀请<font color='#ff0000'>" + intent.getStringExtra("num") + "</font>人获得<font color='#ff0000'>" + intent.getStringExtra("sum") + "元</font>"));
        }
//        one.setText(intent.getStringExtra("one")+"元");
        all.setText("+"+intent.getStringExtra("all")+"元");
        follow_num.setText(intent.getStringExtra("wechatnum"));
        follow_id.setText(UserBean.uid+"");
        tv1.setText(Html.fromHtml("2.在公众号内回复您的ID拿<font color='#ff0000'>"+intent.getStringExtra("one")+"元</font>奖励"));
        tv2.setText(Html.fromHtml("复制公众号:<font color='#69cd1b'>"+intent.getStringExtra("wechatnum")+"</font>和ID:<font color='#69cd1b'>"+UserBean.uid+"</font>发送给好友，好友成功关注公众号并回复ID，你可获得<font color='#ff0000'>"+intent.getStringExtra("one")+"元</font>，最多可邀请<font color='#ff0000'>"+(int)(Double.parseDouble(intent.getStringExtra("all"))/Double.parseDouble(intent.getStringExtra("one")))+"</font>个好友"));
        int sex = getIntent().getIntExtra("sex", 0);
        if (sex==1){
            tv3.setText(Html.fromHtml("你关注公众号：<font color='#69cd1b'>"+intent.getStringExtra("wechatnum")+"</font>，名字叫 <font color='#ff2e2e'>"+intent.getStringExtra("title")+"</font>，然后给他回复<font color='#ff0000'>"+UserBean.uid+"</font>，我就有钱拿了，记得一定不要取消关注哦，谢谢！仅限男性好友关注"));
        }else if (sex==2){
            tv3.setText(Html.fromHtml("你关注公众号：<font color='#69cd1b'>"+intent.getStringExtra("wechatnum")+"</font>，名字叫 <font color='#ff2e2e'>"+intent.getStringExtra("title")+"</font>，然后给他回复<font color='#ff0000'>"+UserBean.uid+"</font>，我就有钱拿了，记得一定不要取消关注哦，谢谢！仅限女性好友关注"));
        }else {
            tv3.setText(Html.fromHtml("你关注公众号：<font color='#69cd1b'>"+intent.getStringExtra("wechatnum")+"</font>，名字叫 <font color='#ff2e2e'>"+intent.getStringExtra("title")+"</font>，然后给他回复<font color='#ff0000'>"+UserBean.uid+"</font>，我就有钱拿了，记得一定不要取消关注哦，谢谢！"));

        }
        tv3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                cm.setText(tv3.getText());
                Toast.makeText(FollowActivity.this, "复制成功 请前往微信粘贴", Toast.LENGTH_SHORT).show();
            }
        });
        follow_num.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                cm.setText(follow_num.getText());
                Toast.makeText(FollowActivity.this, "公众号复制成功", Toast.LENGTH_SHORT).show();

            }
        });
        follow_id.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                cm.setText(follow_id.getText());
                Toast.makeText(FollowActivity.this, "ID复制成功", Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ImmersionBar.with(this).destroy(); //必须调用该方法，防止内存泄漏
    }
}
